package com.fq.myapplication.activity;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import android.content.Intent;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.LinearLayout;

import com.fq.myapplication.MainActivity;
import com.fq.myapplication.R;
import com.fq.myapplication.utils.ThemeManager;

public class SplashActivity extends AppCompatActivity {

    private LinearLayout ll;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_splash);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        // 加载主题设置
        int themeMode = ThemeManager.getThemeMode(this);
        AppCompatDelegate.setDefaultNightMode(themeMode);


        ll = findViewById(R.id.main_ll);
        //设置渐变效果
        setAlphaAnimation();
    }


    /**
     * 设置渐变效果
     */
    private void setAlphaAnimation() {
        //生成动画对象
        AlphaAnimation animation = new AlphaAnimation(0.3f, 1.0f);
        //设置持续时间3s
        animation.setDuration(3000);
        //给控件设置动画
        ll.setAnimation(animation);
        //设置动画监听
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                // jump2Activity();
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    /**
     * 根据首次启动应用与否跳转到相应界面
     */
    //private void jump2Activity() {
    //    SharedPreferences sharedPreferences = getSharedPreferences("data", MODE_PRIVATE);
    //    String First = sharedPreferences.getString("isFirst", "0");
    //    Intent intent = new Intent();
    //    if ("0".equals(First)) {
    //        intent.setClass(this, GuideActivity.class);
    //    }else{
    //        intent.setClass(this, MainActivity.class);
    //    }
    //    startActivity(intent);
    //    finish();
    //}

}